/*
 * Copyright 2015 CPE Lyon - IRC 2013/2016 - Cours de programmation réseau - Groupe H
 *
 * This file is part of BOTT.
 *
 * BOTT is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
 *
 * BOTT is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with BOTT. If not, see http://www.gnu.org/licenses/.
 */

/*
 * Fonctions dédiées au client de messagerie.
 */

#ifndef FONCTIONS_CLIENT_H
#define FONCTIONS_CLIENT_H

#include "protocole.h"

#define MAX_MESSAGES_SAVED 10
#define MAX_MESSAGE_LENGTH 1000

/* Définition de la structure des salons */

typedef struct room room;
struct room {
    int16_t idRoom;  // Big endian
    char roomName[MAX];
    char listMessages[MAX_MESSAGES_SAVED][MAX_MESSAGE_LENGTH];
};

/* Se connecter à un serveur */
int doConnect(int socketDesc, struct sockaddr_in *serverAddr, char *username);

/* Rejoindre un salon */
room doJoin(int socketDesc, struct sockaddr_in *serverAddr, char *chatName, int idUser, room *listChats, room currentRoom);

/* Envoyer un message sur un salon */
void doSay(int socketDesc, struct sockaddr_in *serverAddr, int idUser, room *listRooms, room currentRoom, char *message);

/* Quitter un salon */
int doLeave(int socketDesc, struct sockaddr_in *serverAddr, int idUser, room *listRooms, room leavingRoom);

/* Se déconnecter d'un serveur */
void doDisconnect(int socketDesc, struct sockaddr_in *serverAddr, int idUser);

/* Fonction permettant la notification "ALIVE" du client */
int doAlive(int socketDesc, struct sockaddr_in *sendAddr, int idUser);

/* Changer de salon */
room getRoomByName(char *newRoom, room *listRooms);

/* Mettre à jour l'affichage */
void displayChat(room *listRooms, room currentChat);

/* Traiter un message reçu */
void treatTell(bimp_msg receivedData, room *listRooms);

/* Vérifier si le serveur répond */
void *checkIfAlive(void* transmitData);

#endif